import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 * 所有角色都可以该路由
 */
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },

  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "首页", icon: "dashboard", affix: true },
      },
    ],
  },

  // {
  //   path: "/sys",
  //   component: Layout,
  //   redirect: "/sys/user",
  //   name: "sysManage",
  //   meta: { title: "系统管理", icon: "el-icon-s-help" },
  //   children: [
  //     {
  //       path: "user",
  //       name: "user",
  //       component: () => import("@/views/sys/user"),
  //       meta: { title: "用户管理", icon: "user" },
  //     },
  //     {
  //       path: "role",
  //       name: "role",
  //       component: () => import("@/views/sys/role"),
  //       meta: { title: "角色管理", icon: "link" },
  //     },
  //     {
  //       path: "blackList",
  //       name: "blackList",
  //       component: () => import("@/views/sys/blackList"),
  //       meta: { title: "黑名单", icon: "el-icon-user" },
  //     },
  //   ],
  // },

  // {
  //   path: "/order",
  //   component: Layout,
  //   redirect: "/order/inOrder",
  //   name: "ordertask",
  //   meta: { title: "订单处理", icon: "table" },
  //   children: [
  //     {
  //       path: "allOrders",
  //       name: "allOrders",
  //       component: () => import("@/views/order/allOrders"),
  //       meta: { title: "所有订单", icon: "el-icon-notebook-2" },
  //     },
  //     {
  //       path: "importOrders",
  //       name: "importOrders",
  //       component: () => import("@/views/order/importOrders"),
  //       meta: { title: "批量导入订单", icon: "el-icon-upload" },
  //     },
  //     {
  //       path: "inOrder",
  //       name: "inOrder",
  //       component: () => import("@/views/order/inOrder"),
  //       meta: { title: "订单标记", icon: "el-icon-s-flag" },
  //     },
  //     {
  //       path: "orderProcessing",
  //       name: "orderProcessing",
  //       component: () => import("@/views/order/orderProcessing"),
  //       meta: { title: "订单处理", icon: "el-icon-chat-dot-square" },
  //     },
  //     {
  //       path: "WaitSendOder",
  //       name: "WaitSendOder",
  //       component: () => import("@/views/order/WaitSendOder"),
  //       meta: { title: "待发货", icon: "el-icon-shopping-cart-full" },
  //     },
  //     {
  //       path: "shipped",
  //       name: "shipped",
  //       component: () => import("@/views/order/shipped"),
  //       meta: { title: "已发货", icon: "el-icon-s-platform" },
  //     },
  //     {
  //       path: "sentBack",
  //       name: "sentBack",
  //       component: () => import("@/views/order/sentBack"),
  //       meta: { title: "已寄回", icon: "el-icon-s-claim" },
  //     },
  //     {
  //       path: "cancel",
  //       name: "cancel",
  //       component: () => import("@/views/order/cancel"),
  //       meta: { title: "取消", icon: "el-icon-document-delete" },
  //     },
  //   ],
  // },

  // {
  //   path: "/receiveGoods",
  //   component: Layout,
  //   redirect: "/receiveGoods/goods",
  //   name: "receiveGoodsTask",
  //   meta: { title: "收货", icon: "el-icon-cloudy" },
  //   children: [
  //     {
  //       path: "goods",
  //       name: "goods",
  //       component: () => import("@/views/receiveGoods/goods"),
  //       meta: { title: "收货统计", icon: "el-icon-box" },
  //     },
  //     {
  //       path: "receiptOrder",
  //       name: "receiptOrder",
  //       component: () => import("@/views/receiveGoods/receiptOrder"),
  //       meta: { title: "订单签收", icon: "el-icon-full-screen" },
  //     },
  //   ],
  // },

  // {
  //   path: "/inventorys",
  //   component: Layout,
  //   redirect: "/inventorys/product",
  //   name: "inventorysTask",
  //   meta: { title: "库存", icon: "el-icon-camera" },
  //   children: [
  //     {
  //       path: "product",
  //       name: "product",
  //       component: () => import("@/views/inventorys/product"),
  //       meta: { title: "库存商品", icon: "el-icon-camera-solid" },
  //     },
  //     {
  //       path: "warehouse",
  //       name: "warehouse",
  //       component: () => import("@/views/inventorys/warehouse"),
  //       meta: { title: "仓库管理", icon: "el-icon-box" },
  //     },
  //     {
  //       path: "inventory",
  //       name: "inventory",
  //       component: () => import("@/views/inventorys/inventory"),
  //       meta: { title: "序列号", icon: "el-icon-sell" },
  //     },

  //     {
  //       path: "transferGoods",
  //       name: "transferGoods",
  //       component: () => import("@/views/inventorys/transferGoods"),
  //       meta: { title: "库存调拨", icon: "el-icon-cpu" },
  //     },

  //     {
  //       path: "index",
  //       name: "index",
  //       component: () => import("@/views/inventorys/index"),
  //       meta: { title: "详情页" },
  //       hidden: true,
  //     },
  //   ],
  // },
  // router.addRoutes(arr);
  // 404 page must be placed at the end !!!
  // { path: "*", redirect: "/404", hidden: true },
];

export const asyncRoutes = [
  // {
  //   path: "/test",
  //   component: Layout,
  //   redirect: "/test/test1",
  //   alwaysShow: true,
  //   name: "test",
  //   meta: {
  //     title: "测试模块",
  //     icon: "el-icon-s-help",
  //     roles: ["admin", "manage", "nomal"],
  //   }, // you can set roles in root nav },
  //   children: [
  //     {
  //       path: "test1",
  //       name: "test1",
  //       component: () => import("@/views/test/test1"),
  //       meta: { title: "测试一", icon: "from", roles: ["admin"] },
  //     },
  //     {
  //       path: "test2",
  //       name: "test2",
  //       component: () => import("@/views/test/test2"),
  //       meta: { title: "测试二", icon: "from", roles: ["nomal"] },
  //     },
  //     {
  //       path: "test3",
  //       name: "test3",
  //       component: () => import("@/views/test/test3"),
  //       meta: { title: "测试三", icon: "from", roles: ["nomal"] },
  //     },
  //   ],
  // },

  {
    path: "*",
    redirect: "/404",
    hidden: true,
  },
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
